package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import pojo.Booking;
import service.BookingService;

import java.util.List;

@Controller
public class BookingController {
    @Autowired
    private BookingService bookingService;
    @GetMapping("List")
    public String list(Model model){
        List<Booking> list = bookingService.list();
        model.addAttribute("list",list);
        return "List";
    }
    @GetMapping("toadd")
    public String toadd(){
        return "add";
    }

    @PostMapping("add")
    public String add(Booking booking){
        int add = bookingService.add(booking);
        if (add>0){
            return "redirect:List";
        }
        return null;
    }
}
